package com.seo.controller.proxy.menu;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.seo.pojo.ReturnBody;
import com.seo.service.proxy.menu.sdk.ProxyUserMenuService;
import com.seo.utils.ClientConst;

import lombok.extern.slf4j.Slf4j;

/**
 * menucontroller <br/>
 * 
 * @author shibeilei
 * @version 2017.11.30 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "/proxy/menu")
public class ProxyMenuController {

	@Autowired
	private ProxyUserMenuService proxyUserMenuService;

	@RequestMapping("/userList")
	@ResponseBody
	public ReturnBody userList(HttpServletRequest request, HttpSession session) {
		log.info("获取菜单...");
		ReturnBody rb = ReturnBody.init();

		if (session.getAttribute(ClientConst.SESSION_PROXY_USER_MENULIST) == null) {
			List<Map<String, Object>> menuList = proxyUserMenuService.getAllMenuList();
			if (menuList == null || menuList.isEmpty()) {
				return rb.error("菜单不存在");
			}
			for (Map<String, Object> menu : menuList) {
				menu.put("selected", true);
			}
			rb.put("menuList", menuList);
			session.setAttribute(ClientConst.SESSION_PROXY_USER_MENULIST, menuList);
		} else {
			rb.put("menuList", session.getAttribute(ClientConst.SESSION_PROXY_USER_MENULIST));
		}
		return rb.success();

	}

}
